package com.java1412.json.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.java1412.json.domain.ImsTreeJson;
import com.java1412.json.service.IImsTreeJsonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * json树Controller
 * 
 * @author ruoyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/json/json")
public class ImsTreeJsonController extends BaseController
{
    @Autowired
    private IImsTreeJsonService imsTreeJsonService;

    /**
     * 查询json树列表
     */
    @PreAuthorize("@ss.hasPermi('json:json:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImsTreeJson imsTreeJson)
    {
        startPage();
        List<ImsTreeJson> list = imsTreeJsonService.selectImsTreeJsonList(imsTreeJson);
        return getDataTable(list);
    }

    /**
     * 导出json树列表
     */
    @PreAuthorize("@ss.hasPermi('json:json:export')")
    @Log(title = "json树", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImsTreeJson imsTreeJson)
    {
        List<ImsTreeJson> list = imsTreeJsonService.selectImsTreeJsonList(imsTreeJson);
        ExcelUtil<ImsTreeJson> util = new ExcelUtil<ImsTreeJson>(ImsTreeJson.class);
        util.exportExcel(response, list, "json树数据");
    }

    /**
     * 获取json树详细信息
     */
    @PreAuthorize("@ss.hasPermi('json:json:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imsTreeJsonService.selectImsTreeJsonById(id));
    }

    /**
     * 新增json树
     */
    @PreAuthorize("@ss.hasPermi('json:json:add')")
    @Log(title = "json树", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImsTreeJson imsTreeJson)
    {
        return toAjax(imsTreeJsonService.insertImsTreeJson(imsTreeJson));
    }

    /**
     * 修改json树
     */
    @PreAuthorize("@ss.hasPermi('json:json:edit')")
    @Log(title = "json树", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImsTreeJson imsTreeJson)
    {
        return toAjax(imsTreeJsonService.updateImsTreeJson(imsTreeJson));
    }

    /**
     * 删除json树
     */
    @PreAuthorize("@ss.hasPermi('json:json:remove')")
    @Log(title = "json树", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imsTreeJsonService.deleteImsTreeJsonByIds(ids));
    }
}
